from django.db import models

# Create your models here.
# 用户表
class UserInfo(models.Model):
	username = models.CharField(max_length=32, unique=True)
	password = models.CharField(max_length=32)
	gender = models.IntegerField(choices=[(0, '男'), (1, '女')], default=0, verbose_name='性别')
	age = models.IntegerField(default=0)
	email = models.EmailField(null=True, blank=True)
	phone = models.CharField(max_length=20, null=True)
	userType = models.CharField(max_length=8, choices=[('general', '普通管理员'), ('admin', '管理员')], default='general', verbose_name='用户类型')
	createDateTime = models.DateTimeField(auto_now_add=True)


# 业务线表
class ServiceLine(models.Model):
	name = models.CharField(max_length=32, unique=True)
	userinfos = models.ManyToManyField(UserInfo, related_name='serviceLines')


# 主机表
class Host(models.Model):
	hostname = models.CharField(max_length=32, unique=True)
	hostIp = models.GenericIPAddressField()
	password = models.CharField(max_length=32)
	service_line = models.ForeignKey(ServiceLine, on_delete=models.CASCADE, related_name='hosts')


# 出版社表
class Publisher(models.Model):
	publisher_name = models.CharField(max_length=32, unique=True)


# 图书表
class Book(models.Model):
	book_name = models.CharField(max_length=32)
	book_price = models.IntegerField(default=0)
	pub = models.ForeignKey(Publisher, on_delete=models.CASCADE)




